/**
 * 
 */
package com.seedwill.common.query;

import java.util.List;

import com.seedwill.common.util.ParaCheckHelper;
/**
 * 统计查询项
 * 
 * 在MixedFilter的基础上执行
 * 
 * @author kdyi
 *
 */
public class StatisticClauseItem {

	/**
	 * 项目编号
	 */
	private String statisticId;
	/**
	 * 统计查询语句(比如sum(aColumn))
	 */
	private String statisticClause;
	/**
	 * 附加条件语句
	 */
	private String addClause;
	
	/**
	 * 完整的统计查询语句 自动生成
	 * 只读
	 */
	private String fullStatisticClause;
	
	/**
	 * 附加条件语句用到的参数
	 */
	private List<Object> addPara;
	
	/**
	 * 在统计模式为OBJECT时返回的对象类型
	 */
	private Class reqClazz;
	/**
	 * 返回统计结果模式
	 */
	private StatisticReturnMode returnMode;
	
	/**
	 * 生成统计任务
	 * @throws EvalStatisticTaskException
	 */
	public void evalStatisticTask(String sql, List<Object> paras) throws EvalStatisticTaskException {
		if(statisticClause == null){
			throw new EvalStatisticTaskException("无效的统计语句null");
		}
		if(ParaCheckHelper.validParaStrTrimed(sql)){
			fullStatisticClause = "SELECT "+statisticClause+" "+sql;
			if(ParaCheckHelper.validParaStrTrimed(addClause)){
				fullStatisticClause += " AND " +addClause;
			}
			if(addPara == null){
				addPara = paras;
			}else{
				if(paras!=null && paras.size()>0){
					addPara.addAll(paras);
				}
			}
		}else{
			throw new EvalStatisticTaskException("无效的查询语句"+sql);
		}
	}
	

	public String getAddClause() {
		return addClause;
	}

	public void setAddClause(String addClause) {
		this.addClause = addClause;
	}

	public List<Object> getAddPara() {
		return addPara;
	}

	public void setAddPara(List<Object> addPara) {
		this.addPara = addPara;
	}

	public String getStatisticClause() {
		return statisticClause;
	}

	public void setStatisticClause(String statisticClause) {
		this.statisticClause = statisticClause;
	}

	public String getFullStatisticClause() {
		return fullStatisticClause;
	}


	public Class getReqClazz() {
		return reqClazz;
	}


	public void setReqClazz(Class reqClazz) {
		this.reqClazz = reqClazz;
	}


	public StatisticReturnMode getReturnMode() {
		return returnMode;
	}


	public void setReturnMode(StatisticReturnMode returnMode) {
		this.returnMode = returnMode;
	}


	public String getStatisticId() {
		return statisticId;
	}


	public void setStatisticId(String statisticId) {
		this.statisticId = statisticId;
	}
}
